home *** CD-ROM | disk | FTP | other *** search
Wrap
property pSprite, pColorStart, pColorEnd, pCycleStart, pCycleEnd, pColorRDiff, pColorGDiff, pColorBDiff, pCycleMillis, pCyclesComplete, pColorMode, pCyclePeriod, pColorCycles, pColor1R, pColor1G, pColor1B, pColor2R, pColor2G, pColor2B on getBehaviorDescription me return "COLOR CYCLING" & RETURN & RETURN & "Use this behavior to create a color animation effect. " & "The sprite will change over a period of time, from one color to another. " & "You can use either RGB colors or palette indices. " & "The speed of the color cycle can be set, as can the number of times that the color cycles." & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Color mode (RGB or palette index)" & RETURN & "* Cycle period in seconds" & RETURN & "* Number of cycles" & RETURN & "* Start color" & RETURN & "* End color" & RETURN & RETURN & "To make the color change once (from the start color to the end color) set the number of cycles to 0. " & "To cycle forever, set it to -1." end on getBehaviorTooltip me return "Cycles a sprite's color through a range of either RGB colors or palette indices. " & "Cycling can be continuous or for a specific number of cycles. " & "The cycle rate can also be set." end on beginSprite me pColorMode = resolve(pColorMode) mInitialize(me) end on resolve prop choiceslist = ["Palette", "RGB"] lookup = [#palette, #rgb] return lookup[findPos(choiceslist, prop)] end on prepareFrame me mUpdate(me) end on mInitialize me pSprite = sprite(me.spriteNum) pCyclesComplete = 0.5 pCycleMillis = integer(pCyclePeriod * 1000) mInitColors(me) end on mUpdate me vTime = the milliSeconds vElapsed = vTime - pCycleStart if vTime >= pCycleEnd then pSprite.color = pColorEnd pCyclesComplete = pCyclesComplete + 0.5 case pColorCycles of (-1): mInitColors(me) 0: nothing() otherwise: if pCyclesComplete <= pColorCycles then mInitColors(me) end if end case else if pColorMode = #rgb then vRed = pColorStart.red + (pColorRDiff * vElapsed / pCycleMillis) vGreen = pColorStart.green + (pColorGDiff * vElapsed / pCycleMillis) vBlue = pColorStart.blue + (pColorBDiff * vElapsed / pCycleMillis) pSprite.color = rgb(vRed, vGreen, vBlue) else vRed = pColorStart.paletteIndex + (pColorRDiff * vElapsed / pCycleMillis) pSprite.color = paletteIndex(vRed) end if end if end on mInitColors me if integer(pCyclesComplete * 2) <> (integer(pCyclesComplete) * 2) then vStartColorList = [pColor1R, pColor1G, pColor1B] vEndColorList = [pColor2R, pColor2G, pColor2B] else vStartColorList = [pColor2R, pColor2G, pColor2B] vEndColorList = [pColor1R, pColor1G, pColor1B] end if if pColorMode = #rgb then pColorStart = rgb(vStartColorList[1], vStartColorList[2], vStartColorList[3]) pColorEnd = rgb(vEndColorList[1], vEndColorList[2], vEndColorList[3]) else pColorStart = paletteIndex(vStartColorList[1]) pColorEnd = paletteIndex(vEndColorList[1]) end if pColorRDiff = vEndColorList[1] - vStartColorList[1] pColorGDiff = vEndColorList[2] - vStartColorList[2] pColorBDiff = vEndColorList[3] - vStartColorList[3] pCycleStart = the milliSeconds pCycleEnd = pCycleStart + pCycleMillis pSprite.color = pColorStart end on isOKToAttach me, aSpriteType, aSpriteNum case aSpriteType of #graphic: return getPos([#animGif, #bitmap, #flash, #shape, #text], sprite(aSpriteNum).member.type) <> 0 #script: return 0 end case end on getPropertyDescriptionList me if not (the currentSpriteNum) then exit end if vRect = (the stage).rect vColor = sprite(the currentSpriteNum).color vColorType = vColor.colorType if vColorType = #rgb then vRed = vColor.red vGreen = vColor.green vBlue = vColor.blue else vRed = vColor.paletteIndex vGreen = 0 vBlue = 0 end if vPDList = [:] setaProp(vPDList, #pColorMode, [#comment: "Color mode", #format: #string, #default: "Palette", #range: ["Palette", "RGB"]]) setaProp(vPDList, #pCyclePeriod, [#comment: "Cycle period (seconds)", #format: #float, #default: 3, #range: [#min: 1, #max: 25]]) setaProp(vPDList, #pColorCycles, [#comment: "Color cycles", #format: #integer, #default: 0, #range: [#min: -1, #max: 100]]) setaProp(vPDList, #pColor1R, [#comment: "Start color: palette index or Red component", #format: #integer, #default: vRed, #range: [#min: 0, #max: 255]]) setaProp(vPDList, #pColor1G, [#comment: "Green component", #format: #integer, #default: vGreen, #range: [#min: 0, #max: 255]]) setaProp(vPDList, #pColor1B, [#comment: "Blue Component", #format: #integer, #default: vBlue, #range: [#min: 0, #max: 255]]) setaProp(vPDList, #pColor2R, [#comment: "Final color: palette index or Red component", #format: #integer, #default: 255 - vRed, #range: [#min: 0, #max: 255]]) setaProp(vPDList, #pColor2G, [#comment: "Green component", #format: #integer, #default: 255 - vGreen, #range: [#min: 0, #max: 255]]) setaProp(vPDList, #pColor2B, [#comment: "Blue Component", #format: #integer, #default: 255 - vBlue, #range: [#min: 0, #max: 255]]) return vPDList end